package controller

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

// controllers/base_controller.go

import (
	"gin-zc/util"
)

type BaseController struct{}

func (bc *BaseController) HandleResult(c *gin.Context, data interface{}, err error) {
	if err != nil {
		//c.Error(err)
		c.JSON(http.StatusBadRequest, Error(400, err.Error()))
		c.Abort()
		return
	}
	//result := util.Success(data)
	c.JSON(200, gin.H{"code": 200, "data": data})
}

// 快速处理方法
func (bc *BaseController) OK(c *gin.Context, data interface{}) {
	c.JSON(200, util.Success(data))
}

func (bc *BaseController) HandleError(c *gin.Context, err error) {
	c.Error(err)
	c.Abort()
}
